import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue'),
    redirect:'/ht',
    children:[
      {
        path: '/index',
        name: 'index',
        component: () => import('../views/index.vue'),
        children:[
          {
            path: '/ht',
            name: 'ht',
            component: () => import('../views/ht.vue')
          },
          {
            path: '/xc',
            name: 'xc',
            component: () => import('../views/xc.vue')
          },
          {
            path: '/list',
            name: 'list',
            component: () => import('../views/list.vue')
          },
        ]
      },
      {
        path: '/shop',
        name: 'shop',
        component: () => import('../views/shop.vue'),
        children: [
          {
            path: '/lists',
            name: 'lists',
            component: () => import('../views/lists.vue')
          },
          {
            path: '/fl',
            name: 'fl',
            component: () => import('../views/fl.vue')
          },
          {
            path: '/gg',
            name: 'gg',
            component: () => import('../views/gg.vue')
          },
        ]
      },
      {
        path: '/shops',
        name: 'shops',
        component: () => import('../views/shops.vue'),
        children: [
          {
            path: '/gl',
            name: 'gl',
            component: () => import('../views/gl.vue')
          },
          {
            path: '/fp',
            name: 'fp',
            component: () => import('../views/fp.vue')
          },
          {
            path: '/sh',
            name: 'sh',
            component: () => import('../views/sh.vue')
          },
        ]
      },
      {
        path: '/vip',
        name: 'vip',
        component: () => import('../views/vip.vue'),
        children: [
          {
            path: '/viplist',
            name: 'viplist',
            component: () => import('../views/viplist.vue')
          },
          {
            path: '/vips',
            name: 'vips',
            component: () => import('../views/vips.vue')
          },
        ]
      },
    ]
  }


]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,from,next)=>{
  if(localStorage.getItem('token')){
      next()
    }else{
       if(to.path=='/'){
         next()
       }else {
         next('/')
       }
    }

})

export default router
